<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="../../include/easyui.jsp" %>
<%@ include file="../../include/pGrid.jsp" %>
<%@ include file="../../include/pForm.jsp" %>
<%@ include file="../../include/pWin.jsp"%>
<title>合同更多</title>
<script>
	var gridFn = {};
	$(function(){
		var tabData = parent.consoleFn.getTabData();
		//fn.resetForm({formId:'#queryForm'});
		$('#queryForm').form('load',tabData);
		/*行事件定义*/
		gridFn = $.extend(gridFn,{
			ship: function(data){
				var contractNo = tabData.contractNo;
				var param = {contractNo:contractNo, json: JSON.stringify(data)};
				$.messager.confirm('确认提醒','确定与合同【'+ contractNo +'】建立所属关系吗?',function(r){    
				    if (r){    
				    	$.getJSON('/console/project/rewrite/ship', param, function(result){
						  if(result.flag){
							  	p.tip({msg: '关联成功！'});
							  	p.gridQuery();
							}else{
								p.tip({msg: '关联失败：'+result.msg});
							}
					  	});   
				    }    
				});
			},
			view: function(id,pNo){
				p.gridView({title : "单项工程管理查看", width : 850, height : 430 ,autoMax:true});		
			},
			unship: function(id,contractNo){
				$.messager.confirm('确认提醒','确定解除与合同【'+ contractNo +'】的所属关系吗?',function(r){    
				    if (r){    
				    	$.getJSON('/console/project/rewrite/unship', {id: id}, function(result){
						  if(result.flag){
							  	p.tip({msg: '解绑成功！'});
							  	p.gridQuery();
							}else{
								p.tip({msg: '解绑失败：'+result.msg});
							}
					  	});   
				    }    
				});
				return false;
			}
		});
		/*列表初始化*/
		var gridParam = {
			url : '/console/com.fs.jzzn.pojo.Project/list',
			columns: [[ 
					{field: 'ck', checkbox:true, width: 120}
			    	,{field: 'opt',title: '操作', width: 100,formatter:function(value,row,index){
			    		  if(row.id){
				    		  return "<a  onclick=\"gridFn.unship(\'"+row.id+"\',\'"+ row.contractNo +"\')\" href='javascript:void(0)'>解绑</a>&nbsp;&nbsp;&nbsp;" ;
				    		  //+ "<a  onclick=\"gridFn.view(\'"+ row.pNo +"\')\" href='javascript:void(0)'>详情</a>";
			    		  }
			    	}}
		    		,{field: 'pNo', title: '工程路段编号', width: 130} 
			    	,{field: 'pRoad', title: '工程段落', width: 270}
			    	,{field: 'status', title: '项目状态', width: 120}
			    	,{field: 'pType', title: '专业类别', width: 80}
			    	,{field: 'contractNo', title: '订单编号', width: 240}
			    	,{field: 'pName', title: '项目名称', width: 250}
			    	,{field: 'budgetMoney', title: '立项预算', width: 90}
			    	,{field: 'actualMoney', title: '完工预算', width: 90}
			    	,{field: 'designLength', title: '设计长度', width: 80}
			    	,{field: 'pm', title: '项目经理', width: 100}
			    	,{field: 'marketManager', title: '市场负责人', width: 100}
			    	,{field: 'constructionUnit', title: '建设单位', width: 200}
			    	,{field: 'designUnit', title: '设计单位', width: 120}
			    	,{field: 'operator', title: '运营商', width: 120}
			    	,{field: 'ppm', title: '工程经理', width: 120}
			    	,{field: 'orgNo', title: '所属机构', width: 180,formatter: function(value,row,index){
						return (value || '') + '-' + (row.orgNoName|| '') ;
					}}
			    	,{field: 'pCreateDate', title: '订单日期', width: 120}
			    	,{field: 'subpackage', title: '是否分包', width: 120}
			    	,{field: 'subpackageScale', title: '分包比例', width: 120}
			    	,{field: 'region', title: '区域', width: 120}
			    	,{field: 'priority', title: '优先级', width: 120}
			    	,{field : 'remark',width : 150,title: '备注'}
			    	,{field: 'createTime', title: '创建时间', width: 130}
			    	,{field: 'createrName', title: '创建人', width: 120}
			]],
			queryParams:{
				contractNo : tabData.contractNo,
				contractNo_searchType : 'eq'
			},
			onLoadSuccess:function(data){
				p.total({ 
					tip:'合计:', tipName:'marketManager',
					fields:[
				        {name:'budgetMoney',total:'sum'},
				        {name:'actualMoney',total:'sum'}
					] 
				});
			},
			singleSelect : false
		};
		p.dataGrid = $(p.dataGrid).datagrid( $.extend({}, p.dataGridParam, gridParam));

		/*事件响应*/
		$("#toolbar .easyui-linkbutton").on("click", function() {
			var motion_code = $(this).attr("motion_code");p.btnOneClick($(this));
			switch (motion_code) {
				case "04":
					var row = p.dataGrid.datagrid('getSelections');
					p.gridView({title : "单项工程详情查看", width : 850, height : 430 ,autoMax:true,data: row[0] ,href:"/console/project/view" });	
					break;
				case "05":
					p.gridQuery();
					break;
				case "06":
					wFn.win({
						href:"/console/shipProject/choosebox",
						title:"新增关联立项工程", width : 730,  height : 400,
						callBack:function(data){
							if(data && data.length>0){
								gridFn.ship(data);
							}
						}
					});
					break;
				case "07":
					p.down({filename:'合同更多',url:'/console/project/export',local:true });
					break;
				case "08":
					var data = p.dataGrid.datagrid('getChecked');
					var contractId = fn.data.id;
					 var ids = [],url = [];
					  $.each(data, function(i,item) {
						ids.push(item.id);
					  });
					  ids = ids.join(',');
					  url.push('/console/project/rewrite/print/');
					  url.push(contractId);
					  url.push('?pId='+ids);
					  url = url.join('');
					  window.open(url);  
					break;
				default:
					break;
			}
		});
	});
</script>
</head>
<body  class="easyui-layout">
		<!-- 但行高度33px，多行时 33乘以行数  -->
		<div id="querybar" data-options="region:'north',split:false,border:false" style="height:85px;">
			<div class="easyui-panel" data-options="fit:true,border:false">
				<!-- 查询条件表单，根据配置进行替换  -->
				<form id="queryForm" style="padding: 5px;width: 980px;" >
					<div style="margin-bottom:5px">
					  	<input class="easyui-textbox" name="contractNo" style="width:300px;" data-options="label:'订单编号:'" />
					  	<input class="easyui-textbox" name="contractTitle" style="width:650px;" data-options="label:'订单名称:'" />
					</div>
				
					 <div style="margin-bottom:5px">
					  	<input class="easyui-textbox" name="outContractNo" style="width:300px;" data-options="label:'合同编号:'" />
					  	<input class="easyui-textbox" name="contractName" style="width:650px;" data-options="label:'合同名称:'" />
					 </div>
				</form>
			</div>
		</div>  
	
		<!-- 工具栏按钮 -->
		<div id="toolbar" class="easyui-panel" style="padding:3px;">
			<a href="#" class="easyui-linkbutton" iconCls="icon-view" plain="true" motion_code="04">查看详情</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" motion_code="05">刷新</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" motion_code="06">新增关联工程</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-excel" plain="true" motion_code="07">导出</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-print" plain="true" motion_code="08">打印</a>
		</div>
		
		<!-- 表格 -->
		<div region="center" border="false">
			<table id="dataGrid"></table>
		</div>
</body>
</html>